package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduClassDTO;
import com.zenith.edu.po.vo.EduClassVO;
import com.zenith.edu.service.EduClassService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/class")
@Tag(name = "班级管理", description = "班级管理接口")
public class EduClassController {
    
    @Autowired
    private EduClassService eduClassService;
    
    @SecurePostMapping(value = "createClass",roles = "ADMIN",permission = "class:create")
    @Operation(summary = "创建班级")
    public Result<EduClassVO> createClass(@RequestBody EduClassDTO dto) {
        EduClassVO classVO = eduClassService.createClass(dto);
        return Result.success(classVO);
    }
    
    @SecurePostMapping(value = "/getClassById/{id}",roles = "ADMIN",permission = "class:query")
    @Operation(summary = "根据ID获取班级详情")
    public Result<EduClassVO> getClassById(@PathVariable Long id) {
        EduClassVO classVO = eduClassService.getClassById(id);
        if (classVO == null) {
            return Result.fail("班级不存在");
        }
        return Result.success(classVO);
    }
    
    @SecurePostMapping(value = "updateClass",roles = "ADMIN",permission = "class:update")       
    @Operation(summary = "更新班级信息")
    public Result<EduClassVO> updateClass(@RequestBody EduClassDTO dto) {
        EduClassVO classVO = eduClassService.updateClass(dto);
        return Result.success(classVO);
    }
    
    @SecurePostMapping(value = "/deleteClass/{id}",roles = "ADMIN",permission = "class:delete") 
    @Operation(summary = "删除指定班级")
    public Result<Void> deleteClass(@PathVariable Long id) {
        boolean result = eduClassService.deleteClass(id);
        if (!result) {
            return Result.fail("班级删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getClassList",roles = {"ADMIN"},permission = "class:read")
    @Operation(summary = "获取班级列表")
    public Result<List<EduClassVO>> getClassList() {
        List<EduClassVO> classList = eduClassService.getClassList();
        return Result.success(classList);
    }
}